import { createRouter, createWebHistory } from 'vue-router';

const router = createRouter({
    // 历史储存，可以进行浏览器前进后退功能createWebHistory（）
    history: createWebHistory(),
    routes:[
        {
            path: '',
            redirect: '/LogIn' // 将根路径重定向到 '/home'
        },
        {
            path: '/LogIn',
            name: '登录页',
            component: () =>import('../pages/LogIn.vue')
        },{
            path: '/Main',
            component: () => import('../pages/Main.vue'),
            children: [
                {
                    path: '',
                    redirect: 'Home'
                },
                {
                    path: 'Home',
                    name: 'Home',
                    meta: {
                        module: '首页'
                    },
                    component: () => import('../components/Home/Home.vue')
                },
                {
                    path: 'Management',
                    name: 'Management',
                    meta: {
                        module: '商品管理'
                    },
                    component: () => import('../components/ProManagement/Management.vue')
                },
                {
                    path: 'proOrder',
                    name: 'proOrder',
                    meta: {
                        module: '商品订单'
                    },
                    component: () => import('../components/Order/OrderA.vue')
                },
                {
                    path: 'manage',
                    name: 'manage',
                    meta: {
                        module: '售后管理'
                    },
                    component: () => import('../components/Order/ManageA.vue')
                },
                {
                    path: 'Statistics',
                    name: 'Statistics',
                    meta: {
                        module: '数据统计'
                    },
                    component: () => import('../components/Statistics/Statistics.vue')
                },
                {
                    path: 'Evaluate',
                    name: 'Evaluate',
                    meta: {
                        module: '评价管理'
                    },
                    // @ts-ignore
                    component: () => import('../components/evaluate/Evaluate.vue')
                },
                {
                    path: 'Platform',
                    name: 'Platform',
                    meta: {
                        module: '评价管理'
                    },
                    // @ts-ignore
                    component: () => import('../components/platform/Platform.vue')
                },
                {
                    path: 'User',
                    name: 'User',
                    meta: {
                        module: '用户管理'
                    },
                    // @ts-ignore
                    component: () => import('../components/User/User.vue')
                },
                {
                    path: 'Authority',
                    name: 'Authority',
                    meta: {
                        module: '权限管理'
                    },
                    // @ts-ignore
                    component: () => import('../components/authority/Authority.vue')
                }],
        },{
            path: '/Personage',
            component: () => import('../pages/Personage.vue'),
            children: [{
                path: '',
                redirect: 'center'
            },
            {
                path: 'center',
                name: 'center',
                meta: {
                    module: '个人中心'
                },
                component: () => import('../components/PerCenter/PerCenter.vue')
            },
            {
                path: 'Basics',
                name: 'Basics',
                meta: {
                    module: '基础设置'
                },
                component: () => import('../components/PerCenter/Basics.vue')
            },
            {
                path: 'MSG',
                name: 'MSG',
                meta: {
                    module: '消息中心'
                },
                component: () => import('../components/PerCenter/MSG.vue')
            }]
        }]
})
// @ts-ignore
router.beforeEach((to: object, from: object, next: object) => {
    // 这里是你的权限控制逻辑
    // 检查登录状态、用户权限等
    // 如果符合条件，调用 next() 进行路由切换
    // 如果不符合条件，可以调用 next(false) 阻止路由切换
    let token = localStorage.getItem('token')
    // @ts-ignore
    if (!token && to.path !== '/login') {
        console.log("/login")
        // @ts-ignore
        next('/login')
    } else {
        console.log("/login")
        // @ts-ignore
        next()
    }
});
export default router;
